package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Message;
import com.ruoyi.wechat.domain.ScenicSpots;
import com.ruoyi.wechat.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.ProjectMapper;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.service.IProjectService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 营地其他项目Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@Service
public class ProjectServiceImpl implements IProjectService 
{
    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private IMessageService messageService;

    /**
     * 查询营地其他项目
     * 
     * @param projectId 营地其他项目主键
     * @return 营地其他项目
     */
    @Override
    public Project selectProjectByProjectId(String projectId)
    {
        return projectMapper.selectProjectByProjectId(projectId);
    }

    /**
     * 查询营地其他项目列表
     * 
     * @param project 营地其他项目
     * @return 营地其他项目
     */
    @Override
    public List<Project> selectProjectList(Project project)
    {
        return projectMapper.selectProjectList(project);
    }

    /**
     * 新增营地其他项目
     * 
     * @param project 营地其他项目
     * @return 结果
     */
    @Override
    public int insertProject(Project project)
    {
        project.setProjectId(IdUtils.randomUUID());
        return projectMapper.insertProject(project);
    }

    /**
     * 修改营地其他项目
     * 
     * @param project 营地其他项目
     * @return 结果
     */
    @Override
    public int updateProject(Project project)
    {
        return projectMapper.updateProject(project);
    }

    /**
     * 批量删除营地其他项目
     * 
     * @param projectIds 需要删除的营地其他项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectByProjectIds(String[] projectIds)
    {
        return projectMapper.deleteProjectByProjectIds(projectIds);
    }

    /**
     * 删除营地其他项目信息
     * 
     * @param projectId 营地其他项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectByProjectId(String projectId)
    {
        return projectMapper.deleteProjectByProjectId(projectId);
    }

    /**
     * 审核其他项目并发送消息
     * @param projectId 项目Id
     * @param approve 审核状态
     * @param content 审核内容
     * @return 结果
     */
    @Override
    @Transactional
    public int approve(String projectId, String approve, String content) {
        //营地其他项目条件对象
        Project project = new Project();
        project.setProjectId(projectId);
        project.setApprove(approve);
        //更新审核条件
        int rows = projectMapper.updateProject(project);
        //根据其他项目Id查询对象
        Project project1 = projectMapper.selectProjectByProjectId(projectId);
        //封装消息对象
        Message message = new Message();
        message.setCampId(project1.getCampId());
        message.setContent(content);
        //调用消息
        int row = messageService.insertMessageByApprove(message,"3", approve, project1.getProjectName());

        return rows;
    }
}
